package com.aim.controller.system;

import com.aim.common.annotion.Permission;
import com.aim.common.base.AjaxResult;
import com.aim.common.entity.ZTreeNode;
import com.aim.common.service.FitAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @AUTO 地区控制器
 * @Author AIM
 * @DATE 2019/7/10
 */
@Controller
@RequestMapping("/area")
public class AreaController {

    private static String PREFIX = "system/area/";

    @Autowired
    private FitAreaService areaService;

    /**
     * 列表页面
     */
    @GetMapping
    public String index() {
        return PREFIX + "list.html";
    }

    @PostMapping("/list")
    @Permission
    @ResponseBody
    public Object list(String pcode) {
        List<Map<String, Object>> area = areaService.getArea(pcode);
        return AjaxResult.success(area);
    }

    /**
     * 获取栏目的tree列表
     */
    @RequestMapping(value = "/tree")
    @ResponseBody
    public Object tree() {
        List<ZTreeNode> tree = this.areaService.areaZtree();
        tree.add(ZTreeNode.createParent("中国", 0L));
        return tree;
    }
}
